package ru.alexbykov.nopaginate.item;

import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;

import ru.alexbykov.nopaginate.ResourceTable;
import ru.alexbykov.nopaginate.callback.OnRepeatListener;

/**
 * Created by Alex Bykov on 11.08.2017.
 * You can contact me at: me@alexbykov.ru.
 */
public interface ErrorItem {
    Component getComponent(int position, Component component, ComponentContainer componentContainer,
        OnRepeatListener onRepeatListener);

    ErrorItem DEFAULT = new ErrorItem() {
        @Override
        public Component getComponent(int position, Component component, ComponentContainer componentContainer,
            OnRepeatListener onRepeatListener) {
            Component view = LayoutScatter.getInstance(componentContainer.getContext())
                .parse(ResourceTable.Layout_item_error, null, false);
            Button btnRepeat = (Button) view.findComponentById(ResourceTable.Id_btnRepeat);

            Element element = ElementScatter.getInstance(componentContainer.getContext())
                .parse(ResourceTable.Graphic_no_pagination_button_selector);
            btnRepeat.setBackground(element);

            btnRepeat.setClickedListener(component1 -> {
                if (onRepeatListener != null) {
                    onRepeatListener.onClickRepeat();
                }
            });
            return view;
        }
    };
}
